<template>
	<view>
		<u-popup v-model="classStore.roomConfirmDia" mode="bottom" height="480rpx">
			<view style="margin: 15rpx;">
				<u-form :model="form">
					<u-form-item label="课程链接" label-width="130rpx">
						<u-input v-model="form.RoomLink" placeholder="粘贴网络会议的链接地址" />
					</u-form-item>
					<u-form-item label="房间号" label-width="130rpx">
						<u-input v-model="form.RoomNo" placeholder="输入纯数字的房间号" />
					</u-form-item>
					<u-form-item label="密 码" label-width="130rpx">
						<u-input  v-model="form.Password" placeholder="输入房间密码(如果没有不输入)" /> 
					</u-form-item>
				</u-form>
				<button @click="confirmLess">提交</button>
			</view>
		</u-popup>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from 'vue';
	import { useClassStore } from '@/store/class';
	import { ktlapi } from '@/utils';
	
	/** 扩展内容：教师 */
	defineOptions({ name: 'class-student-expand', inheritAttrs: false });
	
	const classStore = useClassStore();
	const form = ref({
		"RoomLink":"",
		"RoomNo":"",
		"Password":""
	});
	
	function confirmLess(){
		if(form.value.RoomLink.indexOf('tencent') == -1 || !form.value.RoomLink.startsWith('https://')){
			uni.showToast({
				title: '无效链接',
				icon: "error",
				duration: 2000
			});
			return;
		}
		if(form.value.RoomNo === "" || isNaN(form.value.RoomNo.replace(/\-/g,''))){
			uni.showToast({
				title: '无效房间号',
				icon: "error",
				duration: 2000
			});
			return;
		}
		uni.showLoading({
			title: '加载中'
		});
		ktlapi({ 
			action: "Cus_ConfirmLesson",
			data: {
				"ID": classStore.activeItem.UUID,
				"RoomLink":form.value.RoomLink,
				"RoomNo":form.value.RoomNo.replace('\-',''),
				"RoomPwd":form.value.Password
			}
		}).then(res => {
			classStore.activeItem.Status = 2;
			classStore.activeItem.StatusTitle = '已确认';
			classStore.activeItem.RoomLink = form.value.RoomLink;
			classStore.activeItem.RoomNo = form.value.RoomNo;
			classStore.activeItem.RoomPwd = form.value.Password;
			
			classStore.setRoomConfirmDia(false);
			form.value.RoomLink = "";
			form.value.Password = "";
			form.value.RoomNo = "";
			uni.hideLoading();
		});
	}
</script>

<style lang="scss">
</style>